import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class LoveMakeupCouponService {

  serviceUrls: any = {
    queryGoodsListUrl: '/recycleGoods/list', // 查询商品列表
    queryBrandListUrl: '/recycleBrand/list', // 设备品牌List
    queryModelListUrl: '/recycleModel/list', // 设备型号List
    queryLocationListUrl: '/recycleLibrary/list', // 库位List
    brandClassifyUrl: '/recycleCoupon/allRecycleType', // 获取所有品牌系列分类
    queryUserListUrl: '/customer/list', // 获取用户列表
    querySupplierListUrl: '/supplier/list', // 获取供应商 | 货主

    makeupCouponListUrl: '/markUpRecycleCouponInfo/', // 加价券列表
    couponUpdateDetailUrl: '/markUpRecycleCouponInfo/detail/', // 加价券编辑详情
    updateCouponUrl: '/markUpRecycleCouponInfo/', // 新增 or 编辑加价券
    manualReleaseCouponUrl: '/markUpRecycleCouponInfo/issueCoupons', // 手动发放加价券
    stopCouponUrl: '/markUpRecycleCouponInfo/stop/', // 下架加价
    deleteCouponUrl: '/markUpRecycleCouponInfo/', // 删除加价券
    examineCouponUrl: '/markUpRecycleCouponInfo/examine', // 发布加价券

    couponDetailsUrl: '/markUpRecycleCouponInfo/detail/', // 加价券详情
    selectedCouponListUrl: '/recycleGoods/getGoodsByIdList', // 查看已选
    userCouponListUrl: '/recycleCouponUserRecord/', // 用户加价券
    stopUserCouponUrl:'/recycleCouponUserRecord/list' // 停止 or 批量停止 用户券
  };

  constructor(public httpClient: HttpClient) { }

  // 查询用户List
  queryUserList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryUserListUrl, params).toPromise();
  }

  // 获取供应商 | 货主
  querySupplierList() {
    let params = {
      page: 1,
      pageSize: 9999
    }
    return this.httpClient.post(this.serviceUrls.querySupplierListUrl, params).toPromise();
  }

  // 查询二手商品List
  getGoodsList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryGoodsListUrl, params).toPromise();
  }

  // 查询设备品牌List
  getBrandList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryBrandListUrl, params).toPromise();
  }

  // 查询型号List
  getModelList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryModelListUrl, params).toPromise();
  }

  // 查询库位List
  getLocationList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryLocationListUrl, params).toPromise();
  }
  
  // 获取所有品牌系列分类
  getBrandClassifyData() {
    return this.httpClient.get(this.serviceUrls.brandClassifyUrl).toPromise();
  }

  /**
   * 加价券
   * ----------------------------------------------------------------
   */

  // 加价券 List
  getMakeupCouponList(params: any) {
    return this.httpClient.get(this.serviceUrls.makeupCouponListUrl, { params }).toPromise();
  }

  // 新增加价券 POST
  addCouponData(params: any) {
    return this.httpClient.post(this.serviceUrls.updateCouponUrl, params).toPromise();
  }

  // 编辑加价券 PUT
  editCouponData(params: any, id: any) {
    return this.httpClient.put(this.serviceUrls.updateCouponUrl + id, params).toPromise();
  }

  // 获取加价券编辑详情
  getCouponUpdateDetail(id: any) {
    let url = this.serviceUrls.couponUpdateDetailUrl + id;
    return this.httpClient.get(url).toPromise();
  }

  // 手动发放加价券
  manualReleaseCoupon(params: any) {
    return this.httpClient.post(this.serviceUrls.manualReleaseCouponUrl, params).toPromise();
  }

  // 发布加价券
  examineCouponItem(params: any) {
    return this.httpClient.put(this.serviceUrls.examineCouponUrl, params).toPromise();
  }

  // 停止加价券
  stopCouponItem(id: number) {
    let url = this.serviceUrls.stopCouponUrl + id;
    return this.httpClient.put(url, null).toPromise();
  }

  // 删除加价券
  deleteCouponItem(id: number) {
    let url = this.serviceUrls.deleteCouponUrl + id;
    return this.httpClient.delete(url).toPromise();
  }

  // 加价券详情
  getCouponDetails(params: any) {
    return this.httpClient.post(this.serviceUrls.couponDetailsUrl, params).toPromise();
  }

  // 查看已选商品
  getSelectedCouponList(params: any) {
    return this.httpClient.post(this.serviceUrls.selectedCouponListUrl, params).toPromise();
  }

  /**
   * 用户加价券
   * ----------------------------------------------------------------
   */
  // 用户加价券 List
  getUserCouponList(params: any) {
    return this.httpClient.get(this.serviceUrls.userCouponListUrl, { params }).toPromise();
  }
  
  // 用户加价券 Stop(撤回)
  stopUserCoupon(params: any) {
    return this.httpClient.put(this.serviceUrls.stopUserCouponUrl, params).toPromise();
  }
}



